package com.wx.mall.operate.controller;


import com.wx.mall.common.api.CommonResult;
import com.wx.mall.operate.dto.SeckillItemDto;
import com.wx.mall.operate.entity.SeckillItem;
import com.wx.mall.operate.service.impl.SeckillItemServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author j
 * @since 2020-05-28
 */
@RestController
@RequestMapping("/seckill/item")
public class SeckillItemController {

    @Autowired
    SeckillItemServiceImpl seckillItemService;

    @ApiOperation(value = "查询全部")
    @GetMapping("/getFindItem")
    public CommonResult<List<SeckillItem>> getFindItemList(){
        List<SeckillItem> list=seckillItemService.findItem();
        return CommonResult.success(list);
    }

    @ApiOperation(value = "根据id删除")
    @DeleteMapping("/getDeleteItem")
    public CommonResult<Integer> getDeleteItemList(Integer id){
        int i = seckillItemService.deleteOne(id);
        return i==1?CommonResult.success():CommonResult.failed();
    }

    @ApiOperation(value = "根据id修改")
    @PutMapping("/getUpdateItem")
    public CommonResult<Integer> getUpdateItemList(SeckillItemDto dto){
        int i = seckillItemService.updateOne(dto);
        return i==1?CommonResult.success():CommonResult.failed();
    }
}

